package com.zhengb.nettydemos.chapter2.bio;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author zhengbo
 * @date 2019/4/2
 *  时间服务器
 */
public class TimeServer {

    public static void main(String[] args) throws IOException {

        int port = 8080;

        ServerSocket serverSocket = null;
        try {
            serverSocket = new ServerSocket(port);
            System.out.println("The time server start in port:" + port);

            Socket socket;
            while (true) {
                socket = serverSocket.accept();
                System.out.println("server socket accept......");
                //同步阻塞式io 每次请求都会创建一个线程来处理
                new Thread(new TimeServerHandler(socket)).start();
            }
        } finally {
            if (serverSocket != null) {
                System.out.println("server sockect is close");
                serverSocket.close();
            }
        }
    }
}
